package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import gs.*;
	import gs.easing.*;
	import gs.events.TweenEvent;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.tree.AbstractLayoutCache;
	
	public class FramePair extends JFrame
	{
		
		//members define
		private var panelTop:JPanel;
		private var btn_tab_pair:JToggleButton;
		private var panel31:JPanel;
		private var panelPairs:JPanel;
		private var panel11:JPanel;
		private var panel12:JPanel;
		private var labelRefreshTime:JLabel;
		private var btn_refresh:JButton;
		
		//-----------------------------
		private var btn_close:JButton;
		public function FramePair()
		{
			setClosable(false);
			setResizable(false);  
			setBorder(new EmptyBorder());
			btn_close = new JButton();
			btn_close.setLocation(new IntPoint(453, 8));
			btn_close.setSize(new IntDimension(35, 34));
			btn_close.setPreferredSize(new IntDimension(35, 34));
			this.getTitleBar().setCloseButton(btn_close);
			this.setClipMasked(false);
			getContentPane().setClipMasked(false);
			getTitleBar().getFrame().setClipMasked(false);
			
			//component creation
			setSize(new IntDimension(499, 351));
			setPreferredSize(new IntDimension(499, 351));
			var layout0:SoftBoxLayout = new SoftBoxLayout();
			layout0.setAxis(AsWingConstants.VERTICAL);
			layout0.setAlign(AsWingConstants.LEFT);
			layout0.setGap(0);
			getContentPane().setLayout(layout0);
			
			panelTop = new JPanel();
			panelTop.setLocation(new IntPoint(0, 10));
			panelTop.setSize(new IntDimension(499, 19));
			panelTop.setPreferredSize(new IntDimension(499, 19));
			var layout1:FlowLayout = new FlowLayout();
			layout1.setAlignment(AsWingConstants.LEFT);
			layout1.setHgap(25);
			layout1.setVgap(-10);
			panelTop.setLayout(layout1);
			
			btn_tab_pair = new JToggleButton();
			btn_tab_pair.setLocation(new IntPoint(5, 5));
			btn_tab_pair.setSize(new IntDimension(60, 29));
			btn_tab_pair.setPreferredSize(new IntDimension(60, 29));
			btn_tab_pair.setText("label");
			
			panel31 = new JPanel();
			panel31.setLocation(new IntPoint(0, 29));
			panel31.setSize(new IntDimension(499, 270));
			panel31.setPreferredSize(new IntDimension(499, 270));
			var layout2:FlowLayout = new FlowLayout();
			layout2.setAlignment(AsWingConstants.CENTER);
			layout2.setHgap(0);
			layout2.setVgap(11);
			panel31.setLayout(layout2);
			
			panelPairs = new JPanel();
			panelPairs.setLocation(new IntPoint(21, 26));
			panelPairs.setSize(new IntDimension(456, 228));
			panelPairs.setPreferredSize(new IntDimension(456, 228));
			var layout3:GridLayout = new GridLayout();
			layout3.setRows(2);
			layout3.setColumns(3);
			layout3.setHgap(11);
			layout3.setVgap(26);
			panelPairs.setLayout(layout3);
			
			panel11 = new JPanel();
			panel11.setLocation(new IntPoint(0, 309));
			panel11.setSize(new IntDimension(499, 29));
			panel11.setPreferredSize(new IntDimension(499, 29));
			var layout4:CenterLayout = new CenterLayout();
			panel11.setLayout(layout4);
			
			panel12 = new JPanel();
			panel12.setLocation(new IntPoint(147, 0));
			panel12.setSize(new IntDimension(264, 29));
			var layout5:FlowLayout = new FlowLayout();
			layout5.setAlignment(AsWingConstants.CENTER);
			layout5.setHgap(10);
			layout5.setVgap(0);
			panel12.setLayout(layout5);
			
			labelRefreshTime = new JLabel();
			labelRefreshTime.setLocation(new IntPoint(5, 5));
			labelRefreshTime.setSize(new IntDimension(160, 29));
			labelRefreshTime.setPreferredSize(new IntDimension(160, 29));
			labelRefreshTime.setText("label");
			
			btn_refresh = new JButton();
			btn_refresh.setLocation(new IntPoint(100, 0));
			btn_refresh.setSize(new IntDimension(74, 29));
			btn_refresh.setPreferredSize(new IntDimension(74, 29));
			btn_refresh.setText("label");
			
			//component layoution
			getContentPane().append(panelTop);
			getContentPane().append(panel31);
			getContentPane().append(panel11);
			
			panelTop.append(btn_tab_pair);
			
			panel31.append(panelPairs);
			
			panel11.append(panel12);
			
			panel12.append(labelRefreshTime);
			panel12.append(btn_refresh);
			
			//----------------------------------
			setImages();
			panelTop.setClipMasked(false);
			if(m_arPairs.length != 6)
				onBtnRefresh(null);
			setData();
		}
		public static var _frame:FramePair = null;
		public static function show():void
		{
			if(isShowing())
			{
				hide();
				return;
			}
			if(_frame == null)
			{
				_frame = new FramePair();
				PanelMainHelp.getInstance().addChild(_frame);
			}
			_frame.show();
			PanelMainHelp.getInstance().bringToTop(_frame);
			_frame.x = (Engine.W - _frame.width) / 2;
			_frame.y = (Engine.H - _frame.height) / 2;
			_frame.setData();
		}
		
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
		
		private var _mallItems:Array = new Array();
		public function setImages():void
		{
			var img_background:DisplayObject = Client.getUIElement("img_pair_background") as DisplayObject
			setBackgroundDecorator(new AssetBackground(img_background));
			//setSizeWH(img_background.width,img_background.height);
			setSize(new IntDimension(img_background.width, img_background.height));
			setPreferredSize(new IntDimension(img_background.width, img_background.height));
			setLocationXY((Engine.W - img_background.width) / 2,(Engine.H - img_background.height)/2);
			btn_close.wrapSimpleButton(Client.getUIElement("btn_close") as SimpleButton);
			
			btn_tab_pair.setSelected(true);
			btn_tab_pair.wrapSimpleButton(Client.getUIElement("btn_tab_pair") as SimpleButton);
			btn_tab_pair.setText("");
			var group:ButtonGroup = new ButtonGroup();
			group.appendAll(btn_tab_pair);
			
			var filter:GlowFilter;
			var font:ASFont = new ASFont("宋体", 14, false, false, false, false);
			filter = new GlowFilter(0x000000, 1, 2, 2, 10);
			labelRefreshTime.setFont(font);
			labelRefreshTime.setTextFilters(new Array(filter));
			labelRefreshTime.setForeground(ASColor.GREEN);
			labelRefreshTime.setText("剩余刷新时间:00:12:15");
			
			btn_refresh.wrapSimpleButton(Client.getUIElement("btn_pair_refresh_free") as SimpleButton);
			btn_refresh.setText("");

			for(var i:int = 0; i < 6; i++)
			{
				var item:PanePairItem = new PanePairItem;
				panelPairs.append(item);
				_mallItems.push(item);
			}
			btn_refresh.addActionListener(onBtnRefresh);
		}
		private function onBtnRefresh(e:Event):void
		{
			Client.getInstance().sendPacketLogic(1400,[0]);
		}
		public static var m_arPairs:Array = new Array();
		public static var m_tPairRefreshTime:int = 0;
		public static function phPairs_1400(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phPairs_1400", msg);
			var nIndex:uint = 0;
			m_tPairRefreshTime = msg[nIndex++];
			var nCount:uint = msg[nIndex++];
			
			var array:Array = m_arPairs;
			array.splice(0,array.length);
			for(var i:int = 0; i < nCount; i++)
			{
				var obj:Object = new Object();
				array[i] = obj;
				obj.m_nCharId = msg[nIndex++];
				obj.m_szCharName = msg[nIndex++];
				obj.m_nLevel = msg[nIndex++];
				obj.m_nGender = msg[nIndex++];
				obj.m_strBirthday = msg[nIndex++];
				obj.m_nHeight = msg[nIndex++];
				obj.m_strNativeProvince = msg[nIndex++];
				obj.m_strNativeCity = msg[nIndex++];
				obj.m_strFigureURL = msg[nIndex++];
			}
			if(isShowing())
				_frame.setData();
		}
		public function setData():void
		{
			for each(var obj:Object in _mallItems)
			{
				obj.item = null;
			}
			var nIndex:int = 0;
			var nCount:int = 0;
			for each(var item:Object in m_arPairs)
			{
				_mallItems[nIndex++].item = item;
				if(nIndex >= 6)
					break;
			}
			labelRefreshTime.setText("");
		
			if(_timeStaminaUpdate == null)
			{
				_timeStaminaUpdate = new Timer(1000);
				_timeStaminaUpdate.addEventListener(TimerEvent.TIMER,function():void
				{
					FramePair.m_tPairRefreshTime++;
					if(FramePair.m_tPairRefreshTime >= 5*60)
					{
						FramePair.m_tPairRefreshTime = 5*60;
					}
					FramePair.update();
					
				});
				_timeStaminaUpdate.start();
			}
		}
	
		static private var _timeStaminaUpdate:Timer = null;
		public static function update():void
		{
			if(!isShowing())
				return;
			_frame.labelRefreshTime.setText("剩余刷新时间:"+PanelMainHelp.formatTime(5*60-FramePair.m_tPairRefreshTime));
			_frame.btn_refresh.setEnabled(5*60-FramePair.m_tPairRefreshTime == 0);
		}
		
	}
}
import com.*;
import com.Engine.*;
import com.Packet.*;
import com.UI.*;

import flash.display.*;
import flash.events.*;
import flash.external.*;
import flash.filters.*;
import flash.geom.*;
import flash.net.*;
import flash.system.*;
import flash.text.*;
import flash.ui.*;
import flash.utils.*;

//import mx.containers.Panel;

import org.aswing.*;
import org.aswing.border.*;
import org.aswing.border.EmptyBorder;
import org.aswing.colorchooser.*;
import org.aswing.dnd.*;
import org.aswing.event.*;
import org.aswing.ext.*;
import org.aswing.geom.*;
import org.aswing.tree.AbstractLayoutCache;

/**
 * MyPanePairItem
 */
class PanePairItem extends JPanel{
	
	//members define
	private var btnTeam:JButton;
	private var btnFriend:JButton;
	private var panelImage:JPanel;
	private var txtInfo:JTextArea;
	
	/**
	 * MyPanePairItem Constructor
	 */
	public function PanePairItem(){
		//component creation
		setSize(new IntDimension(145, 101));
		setPreferredSize(new IntDimension(145, 101));
		var layout0:EmptyLayout = new EmptyLayout();
		setLayout(layout0);
		
		btnTeam = new JButton();
		btnTeam.setLocation(new IntPoint(19, 73));
		btnTeam.setSize(new IntDimension(49, 28));
		btnTeam.setPreferredSize(new IntDimension(49, 28));
		btnTeam.setText("组队");
		
		btnFriend = new JButton();
		btnFriend.setLocation(new IntPoint(78, 73));
		btnFriend.setSize(new IntDimension(49, 28));
		btnFriend.setPreferredSize(new IntDimension(49, 28));
		btnFriend.setText("交友");
		
		panelImage = new JPanel();
		panelImage.setLocation(new IntPoint(9, 10));
		panelImage.setSize(new IntDimension(50, 50));
		panelImage.setPreferredSize(new IntDimension(50, 50));
		
		txtInfo = new JTextArea();
		txtInfo.setOpaque(false);
		txtInfo.setLocation(new IntPoint(70, 0));
		txtInfo.setSize(new IntDimension(75, 70));
		txtInfo.setPreferredSize(new IntDimension(75, 70));
		txtInfo.setBorder(null);
		txtInfo.setText("小陶");
		txtInfo.setHtmlText("小陶<br>Lv.18<br>15岁/175cm<br>广东深圳");
		txtInfo.setEditable(false);
		txtInfo.setWordWrap(true);
		
		//component layoution
		append(btnTeam);
		append(btnFriend);
		append(panelImage);
		append(txtInfo);
		//---------------------------
		setImages()
	}
	public function setImages():void
	{
		//panelImage.setBorder(new LineBorder(null,ASColor.GREEN));
		btnTeam.wrapSimpleButton(Client.getUIElement("btn_pair_team") as SimpleButton);
		btnTeam.setText("");
		btnFriend.wrapSimpleButton(Client.getUIElement("btn_pair_date") as SimpleButton);
		btnFriend.setText("");
		
		txtInfo.setBackgroundDecorator(null);
		//txtInfo.setText("");
		
		var filter:GlowFilter;
		var font:ASFont = new ASFont("宋体", 12, false, false, false, false);
		filter = new GlowFilter(0x000000, 1, 2, 2, 10);
		txtInfo.setFont(font);
		txtInfo.filters = new Array(filter);
		txtInfo.setForeground(ASColor.WHITE);
		btnTeam.addActionListener(onBtnTeam);
		btnFriend.addActionListener(onBtnFriend);
	}
	private function onBtnTeam(e:Event):void
	{
		if(_item.m_nCharId == CharInfo.charId)
			return;
		PanelMain.showInfoTimeLimit("邀请组队请求发送成功!",Const.INFO_TYPE_SUCCESS);
		Client.getInstance().sendPacketLogic(200,[_item.m_nCharId]);
	}
	
	private function onBtnFriend(e:Event):void
	{
		if(!FrameChar.isArchiveComplete())
		{
			return;
		}
		Client.getInstance().sendPacketLogic(1301,[_item.m_nCharId]);
		FramePair.hide();
	}
	private var _item:Object = null;
	public function set item(val:Object):void
	{
		_item = val;

		/*obj.m_nCharId = msg[nIndex++];
		obj.m_szCharName = msg[nIndex++];
		obj.m_nLevel = msg[nIndex++];
		obj.m_nGender = msg[nIndex++];
		obj.m_strBirthday = msg[nIndex++];
		obj.m_nHeight = msg[nIndex++];
		obj.m_strAddressProvince = msg[nIndex++];
		obj.m_strAddressCity = msg[nIndex++];
		obj.m_strFigureURL = msg[nIndex++];*/
		btnTeam.setEnabled(false);
		btnFriend.setEnabled(false);
		
		txtInfo.setText("");
		if(_item == null)
		{
			panelImage.setBackgroundDecorator(null);
			return;
		}
		if(_item.m_nCharId == null || _item.m_nCharId == 0)
			return;
		
		btnTeam.setEnabled(true);
		btnFriend.setEnabled(true);
		
		var str:String = new String;
		str += _item.m_szCharName+'<br>';
		str += 'Lv.'+_item.m_nLevel+'<br>';
		str += _item.m_strBirthday+'岁/'+_item.m_nHeight+'CM<br>';
		str += _item.m_strNativeProvince+_item.m_strNativeCity;
		txtInfo.setHtmlText(str);
		
		if(_item.m_strFigureURL != null && _item.m_strFigureURL.length != 0)
		{
			
			var lc:LoaderContext = new LoaderContext(true);
			_loader = new Loader();
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function onImageLoaded(e:Event):void
			{
				var loadinfo:LoaderInfo = e.target as LoaderInfo;
				if(_loader != null)
				{  
					var loader2:Loader = new Loader();  
					loader2.contentLoaderInfo.addEventListener(Event.COMPLETE, function loader2Complete(event:Event):void  
					{  
						if(_bmData != null)
						{
							_bmData.dispose();
							_bmData = null;
						}
						var loadinfo:LoaderInfo = event.target as LoaderInfo;
						loadinfo.removeEventListener(Event.COMPLETE,loader2Complete);
						_bmData = new BitmapData(loadinfo.content.width,loadinfo.content.height,true,0x00000000);
						_bmData.draw(loadinfo.content);
						var _bm:Bitmap = new Bitmap(_bmData);
						_bm.scaleX = panelImage.width / _bm.width;
						_bm.scaleY = panelImage.height / _bm.height;
						panelImage.setBackgroundDecorator(new AssetBackground(_bm as DisplayObject));
						loadinfo.loader.unload();
						loadinfo = null;
						if(_loader!= null)
						{
							_loader.unloadAndStop(false);
							_loader = null;
						}
					});  
					loader2.loadBytes(loadinfo.bytes);
				}
			});
			_loader.load(new URLRequest(_item.m_strFigureURL),lc);
		}
		
		
	}
	public function clear():void
	{
		if(_bmData != null)
		{
			_bmData.dispose();
			_bmData = null;
		}

		btnTeam.wrapSimpleButton(new SimpleButton);
		btnFriend.wrapSimpleButton(new SimpleButton);
		var bg:AssetBackground = (this.getBackgroundDecorator() as AssetBackground);
		//var _bm:Bitmap = bg.getDisplay(bg.
		setBackgroundDecorator(null);
		item = null;
		panelImage.setBackgroundDecorator(null);
		if(_loader != null)
		{
			_loader.unloadAndStop(false);
			_loader = null;
		}
	}
	private var _loader:Loader = null; 
	private var _bmData:BitmapData = null;

	//_________getters_________
	

	
	
}